package com.yanghui.dtracing.logback;

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.filter.Filter;
import ch.qos.logback.core.spi.FilterReply;
import lombok.Data;
@Data
public class LogbackFilter extends Filter<ILoggingEvent> {
    private String include;
    @Override
    public FilterReply decide(ILoggingEvent event) {
        String message = event.getMessage();
        if(null == message || "".equals(message)){
            return FilterReply.DENY;
        }
        if(null == include || "".equals(include)){
            return FilterReply.DENY;
        }
        if(message.contains(include)){
            return FilterReply.ACCEPT;
        }
        return FilterReply.DENY;
    }

    @Override
    public void start() {
        if(null != include && !"".equals(include)){
            super.start();
        }
    }
}
